<SecretListHeader
  @isCertTab={{eq this.tab "cert"}}
  @model={{this.backendModel}}
  @baseKey={{this.baseKey}}
  @backendCrumb={{this.backendCrumb}}
  @filter={{this.filter}}
/>
{{#if (and this.noMetadataPermissions this.backendModel.isV2KV)}}
  {{! Show the create button only in the toolbar. Cannot conditional hide this because they could have a specific policy that allows them to create secrets by a certain name }}
  <Toolbar>
    <ToolbarActions>
      <ToolbarSecretLink
        @secret=""
        @mode="create"
        @type="add"
        @queryParams={{hash initialKey=(or this.filter this.baseKey.id) itemType=this.tab}}
        data-test-secret-create={{true}}
      >
        Create Secret
      </ToolbarSecretLink>
    </ToolbarActions>
  </Toolbar>
  <div class="box is-fullwidth is-shadowless has-tall-padding">
    <div class="selectable-card-container one-card">
      <GetCredentialsCard
        @renderInputSearch={{true}}
        @title="View secret"
        @searchLabel="Secret path"
        @subText="Type the path of the secret you want to view. Include a trailing slash to navigate to the list view."
        @placeholder="secret/"
        @type="secret"
        @initialValue={{this.baseKey.id}}
      />
    </div>
  </div>
{{else}}
  {{#let (options-for-backend this.backendType this.tab) as |options|}}
    {{#if (or this.model.meta.total (not this.isConfigurableTab))}}
      <Toolbar>
        {{#if this.model.meta.total}}
          <ToolbarFilters>
            <NavigateInput
              @filterFocusDidChange={{action "setFilterFocus"}}
              @filterDidChange={{action "setFilter"}}
              @filter={{this.filter}}
              @filterMatchesKey={{this.filterMatchesKey}}
              @firstPartialMatch={{this.firstPartialMatch}}
              @baseKey={{get this.baseKey "id"}}
              @shouldNavigateTree={{options.navigateTree}}
              @placeholder={{options.searchPlaceholder}}
              @mode={{if (eq this.tab "cert") "secrets-cert" "secrets"}}
            />
            {{#if this.filterFocused}}
              {{#if this.filterMatchesKey}}
                {{#unless this.filterIsFolder}}
                  <p class="input-hint">
                    <kbd>Enter</kbd>
                    to view
                    {{this.filter}}
                  </p>
                {{/unless}}
              {{/if}}
              {{#if this.firstPartialMatch}}
                <p class="input-hint">
                  <kbd>Tab</kbd>
                  to autocomplete
                </p>
              {{/if}}
            {{/if}}
          </ToolbarFilters>
        {{/if}}

        <ToolbarActions>
          <ToolbarSecretLink
            @secret=""
            @mode="create"
            @type="add"
            @queryParams={{hash initialKey=(or this.filter this.baseKey.id) itemType=this.tab}}
            data-test-secret-create={{true}}
          >
            {{options.create}}
          </ToolbarSecretLink>
        </ToolbarActions>
      </Toolbar>
    {{/if}}

    {{#if this.model.meta.total}}
      {{#each this.model as |item|}}
        {{! Because of the component helper cannot use glimmer nested SecretList::Item }}
        {{#let (component options.listItemPartial) as |Component|}}
          <Component
            @item={{item}}
            @backendModel={{this.backendModel}}
            @backendType={{this.backendType}}
            @delete={{action "delete" item "secret"}}
            @itemPath={{concat options.modelPrefix item.id}}
            @itemType={{options.item}}
            @modelType={{@modelType}}
            @options={{options}}
            @toggleZeroAddress={{action "toggleZeroAddress" item this.backendModel}}
          />
        {{/let}}
      {{else}}
        <div class="box is-sideless">
          {{#if this.filterFocused}}
            There are no
            {{pluralize options.item}}
            matching
            <code>{{this.filter}}</code>, press
            <kbd>ENTER</kbd>
            to add one.
          {{else}}
            There are no
            {{pluralize options.item}}
            matching
            <code>{{this.filter}}</code>.
          {{/if}}
        </div>
      {{/each}}
      {{#if (gt this.model.meta.lastPage 1)}}
        <ListPagination
          @page={{this.model.meta.currentPage}}
          @lastPage={{this.model.meta.lastPage}}
          @link={{concat "vault.cluster.secrets.backend.list" (unless this.baseKey.id "-root")}}
          @models={{compact (array this.backend (if this.baseKey.id this.baseKey.id))}}
        />
      {{/if}}
    {{else}}
      {{#if (eq this.baseKey.id "")}}
        {{#if (and options.firstStep (not this.tab))}}
          <EmptyState @title="Get started with {{capitalize this.backendType}}" @message={{options.firstStep}}>
            <SecretLink
              @mode="create"
              @secret=""
              @queryParams={{hash initialKey=(or this.filter this.baseKey.id) itemType=this.tab}}
              class="link"
            >
              {{options.create}}
            </SecretLink>
          </EmptyState>
        {{else}}
          <EmptyState
            @title="No {{pluralize options.item}} in this backend"
            @message="{{pluralize (capitalize options.item)}}
            in this backend will be listed here.
            {{or options.message (concat 'Add a ' options.item ' to get started.')}}"
          >
            <SecretLink
              @mode="create"
              @secret=""
              @queryParams={{hash initialKey=(or this.filter this.baseKey.id) itemType=this.tab}}
              class="link"
            >
              {{options.create}}
            </SecretLink>
          </EmptyState>
        {{/if}}
      {{else}}
        {{#if this.filterIsFolder}}
          <EmptyState
            @title={{if
              (eq this.filter this.baseKey.id)
              (concat "No " (pluralize options.item) " under &quot;" this.filter "&quot;")
              (concat "No folders matching &quot;" this.filter "&quot;")
            }}
          />
        {{/if}}
      {{/if}}
    {{/if}}
  {{/let}}
{{/if}}